#![allow(non_camel_case_types, non_snake_case)]
use std::mem::ManuallyDrop;
use std::sync::atomic::AtomicU32;
use crate::co;
use crate::decl::*;
use crate::kernel::ffi_types::*;
use crate::ole::privs::*;
use crate::prelude::*;
use crate::vt::*;
#[repr(C)]
pub struct IFileDialogEventsVT {
pub IUnknownVT: IUnknownVT,
pub OnFileOk: fn(COMPTR, COMPTR) -> HRES,
pub OnFolderChanging: fn(COMPTR, COMPTR, COMPTR) -> HRES,
pub OnFolderChange: fn(COMPTR, COMPTR) -> HRES,
pub OnSelectionChange: fn(COMPTR, COMPTR) -> HRES,
pub OnShareViolation: fn(COMPTR, COMPTR, COMPTR, *mut u32) -> HRES,
pub OnTypeChange: fn(COMPTR, COMPTR) -> HRES,
pub OnOverwrite: fn(COMPTR, COMPTR, COMPTR, *mut u32) -> HRES,
}
#[repr(C)]
struct IFileDialogEventsImpl {
vt: IFileDialogEventsVT,
counter: AtomicU32,
OnFileOk: Option<Box<dyn Fn(&IFileDialog) -> HrResult<()>>>,
OnFolderChanging: Option<Box<dyn Fn(&IFileDialog, &IShellItem) -> HrResult<()>>>,
OnFolderChange: Option<Box<dyn Fn(&IFileDialog) -> HrResult<()>>>,
OnSelectionChange: Option<Box<dyn Fn(&IFileDialog) -> HrResult<()>>>,
OnShareViolation: Option<Box<dyn Fn(&IFileDialog, &IShellItem) -> HrResult<co::FDESVR>>>,
OnTypeChange: Option<Box<dyn Fn(&IFileDialog) -> HrResult<()>>>,
OnOverwrite: Option<Box<dyn Fn(&IFileDialog, &IShellItem) -> HrResult<co::FDEOR>>>,
}
impl IFileDialogEventsImpl {
const fn new() -> Self {
Self {
vt: IFileDialogEventsVT {
IUnknownVT: IUnknownVT {
QueryInterface: Self::QueryInterface,
AddRef: Self::AddRef,
Release: Self::Release,
},
OnFileOk: Self::OnFileOk,
OnFolderChanging: Self::OnFolderChanging,
OnFolderChange: Self::OnFolderChange,
OnSelectionChange: Self::OnSelectionChange,
OnShareViolation: Self::OnShareViolation,
OnTypeChange: Self::OnTypeChange,
OnOverwrite: Self::OnOverwrite,
},
counter: AtomicU32::new(1),
OnFileOk: None,
OnFolderChanging: None,
OnFolderChange: None,
OnSelectionChange: None,
OnShareViolation: None,
OnTypeChange: None,
OnOverwrite: None,
}
}
com_interface_custom_iunknown_methods!(Self);
fn OnFileOk(p: COMPTR, pfd: COMPTR) -> HRES {
let box_impl = box_impl::<Self>(p);
hrresult_to_hres(
&match &box_impl.OnFileOk {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
func(&fd)
},
None => Ok(()),
},
)
}
fn OnFolderChanging(p: COMPTR, pfd: COMPTR, psiFolder: COMPTR) -> HRES {
let box_impl = box_impl::<Self>(p);
hrresult_to_hres(
&match &box_impl.OnFolderChanging {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
let si = ManuallyDrop::new(unsafe { IShellItem::from_ptr(psiFolder) });
func(&fd, &si)
},
None => Ok(()),
},
)
}
fn OnFolderChange(p: COMPTR, pfd: COMPTR) -> HRES {
let box_impl = box_impl::<Self>(p);
hrresult_to_hres(
&match &box_impl.OnFolderChange {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
func(&fd)
},
None => Ok(()),
},
)
}
fn OnSelectionChange(p: COMPTR, pfd: COMPTR) -> HRES {
let box_impl = box_impl::<Self>(p);
hrresult_to_hres(
&match &box_impl.OnSelectionChange {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
func(&fd)
},
None => Ok(()),
},
)
}
fn OnShareViolation(
p: COMPTR,
pfd: COMPTR,
psi: COMPTR,
pResponse: *mut u32,
) -> HRES
{
let box_impl = box_impl::<Self>(p);
let ret = match &box_impl.OnShareViolation {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
let si = ManuallyDrop::new(unsafe { IShellItem::from_ptr(psi) });
func(&fd, &si)
},
None => Ok(co::FDESVR::DEFAULT),
};
match ret {
Ok(ret) => {
unsafe { *pResponse = ret.raw(); }
co::HRESULT::S_OK.raw()
},
Err(e) => e.raw(),
}
}
fn OnTypeChange(p: COMPTR, pfd: COMPTR) -> HRES {
let box_impl = box_impl::<Self>(p);
hrresult_to_hres(
&match &box_impl.OnTypeChange {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
func(&fd)
},
None => Ok(()),
},
)
}
fn OnOverwrite(
p: COMPTR,
pfd: COMPTR,
psi: COMPTR,
pResponse: *mut u32,
) -> HRES
{
let box_impl = box_impl::<Self>(p);
let ret = match &box_impl.OnOverwrite {
Some(func) => {
let fd = ManuallyDrop::new(unsafe { IFileDialog::from_ptr(pfd) });
let si = ManuallyDrop::new(unsafe { IShellItem::from_ptr(psi) });
func(&fd, &si)
},
None => Ok(co::FDEOR::DEFAULT),
};
match ret {
Ok(ret) => {
unsafe { *pResponse = ret.raw(); }
co::HRESULT::S_OK.raw()
},
Err(e) => e.raw(),
}
}
}
com_interface_custom! { IFileDialogEvents, IFileDialogEventsImpl: "973510db-7d7f-452b-8975-74a85828d354";
}
impl IFileDialogEvents {
fn_com_closure! { OnFileOk: Fn(&IFileDialog) -> HrResult<()>;
}
fn_com_closure! { OnFolderChange: Fn(&IFileDialog) -> HrResult<()>;
}
fn_com_closure! { OnFolderChanging: Fn(&IFileDialog, &IShellItem) -> HrResult<()>;
}
fn_com_closure! { OnOverwrite: Fn(&IFileDialog, &IShellItem) -> HrResult<co::FDEOR>;
}
fn_com_closure! { OnSelectionChange: Fn(&IFileDialog) -> HrResult<()>;
}
fn_com_closure! { OnShareViolation: Fn(&IFileDialog, &IShellItem) -> HrResult<co::FDESVR>;
}
fn_com_closure! { OnTypeChange: Fn(&IFileDialog) -> HrResult<()>;
}
}